package com.github.od.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.od.bean.ClientInfo;
import com.github.od.service.ClientService;
import com.github.od.util.ClientTokenUtil;
import com.github.od.vo.ObjectRestResponse;

/**
* 服务注册客户端Rest
* 
* @author xieweikun
* @version 2017年11月19日 下午2:53:54
*/
@RestController
@RequestMapping("client")
public class ClientRest {
	
	@Autowired
	private ClientService clientService;
	@Autowired
	private ClientTokenUtil clientTokenUtil;
	
	/**
	 * 1.获取Token
	 * @param clientId
	 * @param secret
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value="/token",method=RequestMethod.POST)
	public ObjectRestResponse getAccessToken(String clientId,String secret) throws Exception {
		ClientInfo apply = clientService.apply(clientId, secret);
		return new ObjectRestResponse<String>().data(clientTokenUtil.generateToken(apply));
	}

	/**
	 * 2.获取允许的服务列表
	 * @param serviceId
	 * @param secret
	 * @return
	 */
	@RequestMapping(value="/allowedClient")
	public ObjectRestResponse getAllowedClient(String serviceId,String secret){
		return new ObjectRestResponse<List<String>>().data(clientService.getAllowedClient(serviceId, secret));
	}
	
}
